<?
session_start();
include('../config.php');
require_once('../classes/class.jira.php');
include("../classes/connect.php");
ini_set('display_errors', 'On');
//include('../header.php');


   function getDisplay($username,$pass,$host){
        $config->username= $username;
        $config->password= $pass;
        $config->port= "";
        $config->host= $host;

        $queryIssue = new Jira($config);
        $array=$queryIssue->getUser($username);
        $response = json_decode($array->responseBody);
        return $response;
        }
?>
   <link href="examples/content/shared/styles/examples-offline.css" rel="stylesheet">
    <link href="styles/kendo.dataviz.min.css" rel="stylesheet">
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
    <!--<link href="../css/header.css" rel="stylesheet">-->

    <script src="js/jquery.min.js"></script>
    <script src="js/kendo.dataviz.min.js"></script>
    <script src="examples/content/shared/js/console.js"></script>
    <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
    
    
  
    <link href="examples/content/shared/styles/kendo.common.min.css" rel="stylesheet">
    <link href="examples/content/shared/styles/kendo.rtl.min.css" rel="stylesheet">
    <link href="examples/content/shared/styles/kendo.default.min.css" rel="stylesheet">

    <!--<script src="js/jquery.min.js"></script>-->
    <script src="js/kendo.web.min.js"></script>
    <script src="examples/content/shared/js/console.js"></script>
    
    
    <link rel="stylesheet" href="../css/header.css" type="text/css" media="all">     

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JIRA COMMUNI</title>
<link href="../css/demo.css" rel="stylesheet" type="text/css" />
<!--<link rel="stylesheet" type="text/css" href="paginate/styles/style.css" />-->
</head>
<body class="sonata-bc" >
    <div class="navbar navbar-fixed-top">
        <div class="navbar-inner">
            <div class="container-fluid header-bar-container">
                <div class="header-bar-top">
                    <a class="brand">
                        <img src="images/logo_white.png" alt="JiraPortal">Recruitment Application      
                    </a>
                </div>
            </div>

            <div class="container-fluid">
                <a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>
                <div class="nav-collapse">
                    <ul class="nav" id="menu" style="background-color: #1C2326">
                        <li class="active">
                            <a href="../home.php">Applications</a>
                        </li>
                        <li >
                            <a class="dropdown-toggle" data-toggle="dropdown" href="reportdash.php"> Reports</a> 
                        </li>
                        
                         <li >
                            <a class="dropdown-toggle" data-toggle="dropdown" href="delayreport.php"> Delay Reports</a> 
                        </li>

                        <div class="navbar-text" style="top: 18px;">
                          
                    <p style="color: #FFFFFF;font-size: 15px;font-weight: 100;"> Welcome <?php

                            $display=  getDisplay($username, $pass, $host);
                           echo $display->displayName;
                        
                        ?> [ <a href="logout.php">Logout</a> ]<p>
                </div>
            </div>
        </div>

        </div>
    </div>
<!--    <div>
    <a class="offline-button" href="report.php">Back</a>
    <a class="offline-button" href="../home.php">Home</a>
    </div>-->
	  

<div class="homecontainer">
  
	<div class="taskdiv">	
            
<div id="example" class="k-content">
            <div class="chart-wrapper">
                
                <div class="postdrop" style="float: left; margin-left: 64px;" >
					<p class="statustext">Select a status: </p>
                                        <select id="status" class="sele">
						<option value="All">All</option>	
						<option value="OpenCV - Shortlisted">OpenCV - Shortlisted</option>
						<option value="Shortlisted - Test Called">Shortlisted - Test Called</option>
						<option value="Shortlisted - Interview Called">Shortlisted - Interview Called</option>
						<option value="Test Called - Tested">Test Called - Tested</option>
						<option value="Interview Called - Interviewed">Interview Called - Interviewed</option>
						<option value="Tested - Final Interview Called">Tested - Final Interview Called</option>						
						<option value="Interviewed - Test Called">Interviewed - Test Called</option>
						<option value="Final Interview Called - Final Interviewed">Final Interview Called - Final Interviewed</option>
						<option value="Final Interviewed - Selected">Final Interviewed - Selected</option>
						<option value="Selected - Offered">Selected - Offered</option>
						<option value="Offered - Joined">Offered - Joined</option>					 
					 </select>
				</div>
				<div class="ajaxload" id="loading-image">
				 <img src="../images/ajax.gif">
				 </div>
               
            </div>
		 <div id="chart"></div>	
            <script>
$(document).ready(function() {
	setTimeout(function() {
		// Initialize the chart with a delay to make sure
		// the initial animation is visible
		createChart();

		$("#example").bind("kendo:skinChange", function(e) {
			createChart();
		});
	}, 400);
$('#loading-image').bind('ajaxStart', function(){
    $(this).show();
}).bind('ajaxStop', function(){
    $(this).hide();
});

selection('All');
$('#status').bind('change', function() {
	var select = $('#status').val();
	selection(select);
});
function selection(selected){
	var nodates = new Array();
	for(i=0;i<=30;i++){
		nodates.push(i);
	}
	$.ajax({
		  url: 'ajax.php?fromdate=""&todate=""',
		  dataType:'json'
		}).done(function(json) {
		if(selected == 'All'){
			var openTOshort = new Array();
			var shortTOtestcall = new Array();
			var shortTOinterviewcall = new Array();
			var testcallTOtested = new Array();
			var interviewcallTOinterviewed = new Array();
			var testedTOfinalinterviewcall = new Array();
			var interviewedTOtestcall = new Array();
			var finalinterviewcallTOfinalinterviewed = new Array();
			var finalinterviewedTOselected = new Array();
			var selectedTOoffer = new Array();
			var offerTOjoin = new Array();
			for(index=0;index<nodates.length;index++){
				var CopenTOshort = 0;
				var CshortTOtestcall = 0;
				var CshortTOinterviewcall = 0;
				var CtestcallTOtested = 0;
				var CinterviewcallTOinterviewed = 0;
				var CtestedTOfinalinterviewcall = 0;
				var CinterviewedTOtestcall = 0;
				var CfinalinterviewcallTOfinalinterviewed = 0;
				var CfinalinterviewedTOselected = 0;
				var CselectedTOoffer = 0;
				var CofferTOjoin = 0;
				$.each(json , function(i,element) {
					if(datediff(element[0],element[1]) == index){
						CopenTOshort++;
					}
					if(datediff(element[1],element[8]) == index  && (element[7] == "null" || element[7]>element[8])){
						CshortTOtestcall++;
					}
					if((datediff(element[1],element[7]) == index && element[7] != "null")){
						CshortTOinterviewcall++;
					}
					if(datediff(element[8],element[3]) == index){
						CtestcallTOtested++;
					}	
					if(datediff(element[7],element[2]) == index){
						CinterviewcallTOinterviewed++;
					}					
					if(datediff(element[3],element[10]) == index){
						CtestedTOfinalinterviewcall++;
					}
					if(datediff(element[2],element[8]) == index){
						CinterviewedTOtestcall++;
					}
					if(datediff(element[10],element[11]) == index){
						CfinalinterviewcallTOfinalinterviewed++;
					}
					if(datediff(element[11],element[4]) == index){
						CfinalinterviewedTOselected++;
					}
					if(datediff(element[4],element[6]) == index){
						CselectedTOoffer++;
					}
					if(datediff(element[6],element[9]) == index){
						CofferTOjoin++;
					}
				});
				openTOshort.push(CopenTOshort);
				shortTOtestcall.push(CshortTOtestcall);
				shortTOinterviewcall.push(CshortTOinterviewcall);
				testcallTOtested.push(CtestcallTOtested);
				interviewcallTOinterviewed.push(CinterviewcallTOinterviewed);
				testedTOfinalinterviewcall.push(CtestedTOfinalinterviewcall);
				interviewedTOtestcall.push(CinterviewedTOtestcall);
				finalinterviewcallTOfinalinterviewed.push(CfinalinterviewcallTOfinalinterviewed);
				finalinterviewedTOselected.push(CfinalinterviewedTOselected);
				selectedTOoffer.push(CselectedTOoffer);
				offerTOjoin.push(CofferTOjoin);
				
			}
			createChart(nodates,openTOshort,shortTOtestcall,shortTOinterviewcall,testcallTOtested,interviewcallTOinterviewed,testedTOfinalinterviewcall,interviewedTOtestcall,finalinterviewcallTOfinalinterviewed,finalinterviewedTOselected,selectedTOoffer,offerTOjoin,'NULL','NULL');
		}
		else{
			if(selected == 'OpenCV - Shortlisted'){
				var selectedName=selected;
				var data = new Array();
                               // alert(data[2]);
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[0],element[1]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Shortlisted - Test Called'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[1],element[8]) == index  && (element[7] == "null" || element[7]>element[8])){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Test Called - Tested'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[8],element[3]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Tested - Interview Called'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if((datediff(element[3],element[7]) == index)  && (element[7]>element[8])){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Interview Called - Interviewed'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[7],element[2]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Interviewed - Final Interview Called'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[2],element[10]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Final Interview Called - Final Interviewed'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[10],element[11]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Final Interviewed - Selected'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[11],element[4]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Selected - Offered'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[4],element[6]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
			if(selected == 'Offered - Joined'){
				var selectedName=selected;
				var data = new Array();
				for(index=0;index<nodates.length;index++){
					var currdata = 0;
					$.each(json , function(i,element) {
						if(datediff(element[6],element[9]) == index){
							currdata++;
						}
					});
				data.push(currdata);
				}
				createChart(nodates,'NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL','NULL',data,selectedName);
			}
		
		}
		
		});

}	
});

function datediff(date1,date2){
	var date_1 = new Date(date1*1000);
	var date_2 = new Date(date2*1000);

	var timeDiff = Math.abs(date_2.getTime() - date_1.getTime());
	var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
	return diffDays;
}
function createChart(nodates,openTOshort,shortTOtestcall,shortTOinterviewcall,testcallTOtested,testedTOinterviewcall,interviewcallTOinterviewed,interviewedTOfinalinterviewcall,finalinterviewcallTOfinalinterviewed,finalinterviewedTOselected,selectedTOoffer,offerTOjoin,selected,selectedName) {
	if(selected == 'NULL'){
		$("#chart").kendoChart({
		theme: $(document).data("kendoSkin") || "default",
		title: {
			text: "Time took to pass between Two statuses"
		},
		
		series: [{
			type: "line",
			data: openTOshort,
			color: "#00FFFF",
			name: "Open - Short"
		},{
			type: "line",
			data: shortTOtestcall,
			color: "#330000",
			name: "Short - Test Call"
		},{
			type: "line",
			data: testcallTOtested,
			color: "#336600",
			name: "Test Call - Tested"
		},{
			type: "line",
			data: testedTOinterviewcall,
			color: "#33FF00",
			name: "Tested - Interview Call"
		},{
			type: "line",
			data: interviewcallTOinterviewed,
			color: "#663333",
			name: "Interview Call - Interviewed"
		},{
			type: "line",
			data: interviewedTOfinalinterviewcall,
			color: "#6633CC",
			name: "Interviewed - Final Interview Call"
		},{
			type: "line",
			data: finalinterviewcallTOfinalinterviewed,
			color: "#99FF00",
			name: "Final Interview Call - Final Interviewed"
		},{
			type: "line",
			data: finalinterviewedTOselected,
			color: "#CC9900",
			name: "Final Interviewed - Selected"
		},{
			type: "line",
			data: selectedTOoffer,
			color: "#FF0000",
			name: "Selected - Offer"
		},{
			type: "line",
			data: offerTOjoin,
			color: "#FFFF00",
			name: "Offer - Join"
		}],

		tooltip: {
				visible: true
		},
		categoryAxis: {
			title: { text: "No of Days Passed" },
			categories: nodates
		},
		valueAxis: {
			majorUnit: 2,
			title: { text: "No of Applications" },
			min: 0 
		 }
	});
	}
	else{
            //alert(selected); 
	$("#chart").kendoChart({
            
		theme: $(document).data("kendoSkin") || "default",
		title: {
			text: "Time took to pass between Two statuses"
		},
		
		series: [{
			type: "line",
			data: selected,
			name: selectedName
		}],

		tooltip: {
				visible: true
		},
		categoryAxis: {
			title: { text: "No of Days Passed" },
			categories: nodates
		},
		valueAxis: {
			majorUnit: 20,
			title: { text: "No of Applications" },
			min: 0 
		 }
	});
	
	}
}

            </script>
        </div>
	</div>
    </div>
		<style scoped>
                .chart-wrapper {
                	height: 90px;
                }
                
                .chart-wrapper .k-chart {
                    height: 500px;
                }
            </style>
            
          
</body>
</html>
